<script>
    var page_list = "advertise_list";
    $(function () {
        $("body").layout();
        grid_init($("#grid"), {
            singleSelect: false,
            columns: [[
                {field: 'o.id', checkbox: true, title: '项目ID', width: 80},
                {field: 'o.code', title: '金融代码', width: 110},
                {field: 'o.companyname', title: '名称', width: 200},
                {field: 'o.imgUrl', title: '图片地址', width: 280},
                {
                    field: 'o.advertiseUrl', title: '广告URL', width: 280, formatter: function (value, row, index) {
                        if(value == undefined){
                            return "";
                        }else{
                            return '<a href="'+value+'" target="_blank">'+value+'</a>';
                        }
                    }
                },
                {field: 'o.content', title: '内容', width: 300},
                {field: 'o.duration', title: '持续时间(天)', width: 120},
                {field: 'o.remark', title: '备注', width: 150},
                {
                    field: 'o.deleteFlag', title: '是否启用', width: 100, formatter: function (value, row, index) {
                        if (value == "1") {
                            return "禁用";
                        } else if (value == "0") {
                            return "启用";
                        }
                        return value;
                    }
                },
                {
                    field: 'o.isHomePage', title: '是否主页显示', width: 150, formatter: function (value, row, index) {
                        if (value == "1") {
                            return "显示";
                        } else if (value == "0") {
                            return "不显示";
                        }
                        return value;
                    }
                },

                {field: 'u.realName', title: '创建人', width: 80},
                {field: 'o.createTime', title: '创建时间', width: 150}]],
            _order: "o.code desc,o.createTime desc",
            _append: [],//隐藏列
            _page: page_list,
            _table: "bs_ad as o left join bs_user as u on o.createBy = u.id",
            _exportTitle: false,//不打印
            _context_handle: [{
                text: "详情",
                icon: "icon-info",
                handle: function (index, row) {
                    j_showWin({
                        url: 'logistics/advertise/info.html?keyId=' + this.getFieldValue(row, "o.id"),
                        title: '广告信息',
                        iconCls: 'icon-form-info'
                    })
                }
            }, {
                text: "编辑",
                //auth: "update",
                icon: "icon-edit",
                handle: function (index, row) {
                    j_showWin({
                        url: 'logistics/advertise/edit.html?keyId=' + this.getFieldValue(row, "o.id"),
                        title: '编辑广告信息',
                        iconCls: 'icon-form-edit'
                    })
                }
            }, {
                text: "禁用",
                //auth: "delete",
                icon: "icon-config-delete",
                handle: function (index, row) {
                    var grid = $(this);
                    var self = this;
                    if (self.getFieldValue(row, "o.deleteFlag") == 0) {
                        $.messager.confirm('系统提示', '您确认删该广告信息吗?', function (r) {
                            if (r) {
                                self.focus();
                                showLoading();
                                fy_api.ajax({
                                    url: "advertise/delete.do?_t=" + new Date().getTime(),
                                    data: {"keyId": self.getFieldValue(row, "o.id")},
                                    success: function (data) {
                                        hideLoading();
                                        if (isSuccess(data)) {
                                            j_tip(data.msg, 'success');
                                            grid.datagrid("reload");
                                        } else {
                                            $.messager.alert('系统提示', data.msg, 'error', function () {
                                                self.focus();
                                            });
                                        }
                                    }
                                });
                            } else {
                                self.focus();
                            }
                        });
                    } else {
                        j_tip("该广告信息已经是禁用状态", 'error');
                    }
                }
            }],
            toolbar: '#grid_toolbar',
            searchDiv: '#grid_search'
        });
        $("input").blur();
        $("#btnBatchDelete").click(function () {
            initBatchOperation(grid_get("grid"), "advertise/batchDelete.do", "禁用");
        })
    });

    //用户列表
    $('#user').inputgrid({
        idField: 'o.id',
        textField: 'o.loginName',
        searchField: ['o.id', 'o.loginName'],//查询字段多字段匹配
        columns: [[
            {field: 'o.id', title: '员工编号'},
            {field: 'o.loginName', title: '员工姓名'},
            {field: 'o.realName', title: '真实姓名'}
        ]],
        _page: parent.page_list,
        _append: [],//隐藏列
        _table: "bs_user as o"
    });

    //金融代码
    $('#company').inputgrid({
        idField: 'o.code',
        textField: 'o.name',
        searchField: ['o.code', 'o.name'],//查询字段多字段匹配
        columns: [[
            {field: 'o.code', title: '金融代码'},
            {field: 'o.name', title: '名称'},
            {field: 'o.address', title: '地址'}
        ]],
        _page: parent.page_list,
        _append: [],//隐藏列
        _table: "company as o",
        _db: "slave"
    });
</script>
<style>
    .datagrid-cell, .datagrid-cell-group, .datagrid-header-rownumber, .datagrid-cell-rownumber {
        text-overflow: ellipsis;
    }
</style>
<div id="grid_search"
     data-options="region:'north',height:'auto',hideExpandTool: true,hideCollapsedContent: false,collapsedContent:function(){return '查询条件(已隐藏)'}"
     style="border-top:none;border-left:none;border-right:none;" class="search-form">
    <div class="div-item">
        <div class="div-label">内容：</div>
        <input type="text" name="content" clear/>
    </div>
    <div class="div-item">
        <div class="div-label">金融代码：</div>
        <input name="o.code" type="hidden" id="code" clear/>
        <input type="text" id="company" clear/>
    </div>
    <div class="div-item">
        <div class="div-label">创建人：</div>
        <input type="hidden" id="createBy" name="o.createBy" clear/>
        <input type="text" id="user" clear/>
    </div>
    <div class="div-item">
        <div class="div-label" style="width: 80px;">状态：</div>
        <select name="o.deleteFlag" id="deleteFlag" style="width: 60px;" value="${deleteFlag}" clear>
            <option value="">所有</option>
            <option value="0">启用</option>
            <option value="1">禁用</option>
        </select>
    </div>

</div>
<div data-options="region:'center',title:false,border:false" id="divCenter" style="">
    <table id="grid"></table>
</div>
<div id="grid_toolbar" style="padding:3px;">
    <a href="javascript:void(0)" class="easyui-linkbutton <!--auth-button-->" action="add"
       data-options="plain:true,iconCls:'icon-config-add'"
       onclick="j_showWin({url:'logistics/advertise/edit.html',title:'添加广告',iconCls: 'icon-form-add'})">添加</a>
    <a href="javascript:void(0)" class="easyui-linkbutton <!--auth-button-->" action="delete"
       data-options="plain:true,iconCls:'icon-config-delete'" id="btnBatchDelete">批量禁用</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'layout-button-up'"
       onclick="var button=$(this);if(button.linkbutton('options').iconCls=='layout-button-up'){$('body').layout('collapse','north');button.linkbutton({iconCls:'layout-button-down'})}else{$('body').layout('expand','north');button.linkbutton({iconCls:'layout-button-up'})}button.linkbutton('disable');setTimeout(function(){button.linkbutton('enable');},200)"
       style="float:right"></a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-help'" id="help"
       style="float:right"></a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-button-refresh'"
       onclick="grid_get('grid')[0].search(true)" style="float:right">重置</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-search'"
       onclick="grid_get('grid')[0].search()" style="float:right">查询</a>
</div>